<?php

namespace App\Containers\AppSection\Moneybox\Tasks;

use App\Ship\Exceptions\InternalErrorException;
use App\Ship\Parents\Tasks\Task;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

class ConnectionCheckTask extends Task
{
    protected Client $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    public function run(string $uuid, string $text): ResponseInterface
    {
        try {
            return $this->client->post(config('appSection-moneybox.url') . 'echo/', [
                'json'=>[
                    'uuid' => $uuid,
                    'text' => $text,
                ],
                'headers' => [
                    'Content-Type' => 'application/json'
                ],
            ]);
        } catch (\Exception $exception) {
            throw new InternalErrorException();
        }

    }
}
